import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.IOException;

class FrameMain extends JFrame implements ActionListener {
    JPanel contentPane;
    JMenuBar mb1 = new JMenuBar();
    JMenu readr = new JMenu("读者");
    JMenu book = new JMenu("图书");
    JMenu help = new JMenu("帮助");
    JMenu exit = new JMenu("退出");
    //JMenu 借阅=new JMenu("借阅");
    JMenuItem r1 = new JMenuItem("浏览读者信息");
    JMenuItem b1 = new JMenuItem("浏览图书信息");
    JMenuItem b2 = new JMenuItem("增加图书");
    JMenuItem b3 = new JMenuItem("删除图书");
    JMenuItem b4 = new JMenuItem("修改图书信息");
    JMenuItem h1 = new JMenuItem("使用网络信息帮助");
    JMenuItem h2 = new JMenuItem("读取java文件帮助信息");
    JMenuItem e1 = new JMenuItem("退出系统");

    //JMenuItem 借书记录=new JMenuItem("借书记录");
//JMenuItem 还书记录=new JMenuItem("还书记录");
    FrameMain() {
        setTitle("图书馆信息管理系统");
        readr.add(r1);
        book.add(b1);
        book.add(b2);
        book.add(b3);
        book.add(b4);
        help.add(h1);
//借阅.add(借书记录);
//借阅.add(还书记录);
        help.add(h2);
        exit.add(e1);
        mb1.add(readr);
        mb1.add(book);
//mb1.add(借阅);
        mb1.add(help);
        mb1.add(exit);
        setJMenuBar(mb1);
        r1.addActionListener(this);
        b1.addActionListener(this);
        b2.addActionListener(this);
        b3.addActionListener(this);
        b4.addActionListener(this);
        h1.addActionListener(this);
        h2.addActionListener(this);
        e1.addActionListener(this);
        setBounds(200, 200, 500, 500);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == r1) {
            new ShowReader();
        } else if (e.getSource() == b1) {
            new ShowBook();
        } else if (e.getSource() == b2) {
            new InsertBook();
        } else if (e.getSource() == b3) {
            new Delete();
        } else if (e.getSource() == b4) {
            new Modify();
        } else if (e.getSource() == h1) {
            Help1 flink = new Help1();
        } else if (e.getSource() == h2) {
            class Help2 extends JFrame {
                Help2() {
                    byte b[] = new byte[30];
                    JTextArea text = new JTextArea(20, 20);
                    setSize(330, 300);
                    setVisible(true);
                    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    add(text, BorderLayout.CENTER);
                    try {
                        FileInputStream input = new FileInputStream("help.java");
                        ProgressMonitorInputStream in = new ProgressMonitorInputStream(this, "读取help文件", input);
                        ProgressMonitor p = in.getProgressMonitor();
                        while (in.read(b) != -1) {
                            String s = new String(b);
                            text.append(s);
                            Thread.sleep(200);
                        }
                    } catch (InterruptedException e) {
                    } catch (IOException e) {
                    }
                }
            }
            new Help2();
        } else if (e.getSource() == e1) {
            System.exit(0);
        }
    }
}
